package own.stu.jobgib.playown.event;

import com.google.common.eventbus.EventBus;
import own.stu.jobgib.playown.event.event.CarAddInfoEvent;
import own.stu.jobgib.playown.event.event.PositionInfoEvent;
import own.stu.jobgib.playown.event.model.Car;
import own.stu.jobgib.playown.event.subcribe.PositionSubscriber;

import java.util.concurrent.TimeUnit;

public class EventBusTest {

    public static void main(String[] args) throws InterruptedException {
        EventBus eventBus = new EventBus();
        eventBus.register(new PositionSubscriber());

        new Thread(() -> {
            Car car = new Car("ferri");
            eventBus.post(new CarAddInfoEvent(car));
            for (int i = 0; i < 10; i++) {
                eventBus.post(new PositionInfoEvent(car, i + "", i * 2 + ""));
            }
        }).start();
        System.out.println(" main ... continue ");
        TimeUnit.SECONDS.sleep(3);
    }
}
